
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        2/7/2009
 * PROJECT:             MCWEBSITE
 * PURPOSE:             LanguageDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class LanguageDAL
    {
        #region  Properties
		 
		public static string FIELD_LANGUAGECODE = "LanguageCode";  
		public static string FIELD_LANGUAGENAME = "LanguageName";  
		public static string FIELD_DESCRIPTION = "Description"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of Language
        /// </summary>
        /// <param name="LanguageCode">Primary Keys</param>
        /// <returns>Collection of LanguageInfo</returns>
        public static LanguageInfo SelectOne(string LanguageCode)
        {
            LanguageInfo _LanguageInfo = new LanguageInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_conf_LanguageSelectOne", LanguageCode);
                if (dr.Read())
                    setLanguageInfo(dr, ref _LanguageInfo);
                return _LanguageInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all Language
        /// </summary>
        /// <returns>Collection of LanguageInfo</returns>
        public static List<LanguageInfo> SelectAll()
        {
            List<LanguageInfo> lstLanguage = new List<LanguageInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_conf_LanguageSelectAll");
                setListLanguageInfo(ref dr, ref lstLanguage);
                return lstLanguage;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="Languagenfo">Modify this method adapting your need</param>
        /// <returns>Collection of LanguageInfo</returns>
        public static List<LanguageInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<LanguageInfo> lstLanguage = new List<LanguageInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_conf_LanguageSelectByFilters");
                setListLanguageInfo(ref dr, ref lstLanguage);
                return lstLanguage;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert Language
        /// </summary>
        /// <param name="LanguageInfo">Entity of Language</param>
        /// <returns>error code</returns>
        public static int Insert(LanguageInfo _LanguageInfo)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_conf_LanguageInsert" 
											, _LanguageInfo.LanguageName
											, _LanguageInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update Language
        /// </summary>
        /// <param name="LanguageInfo">Entity of Language</param>
        /// <returns>error code</returns>
        public static int Update(LanguageInfo _LanguageInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_conf_LanguageUpdate"
											, _LanguageInfo.LanguageCode
											, _LanguageInfo.LanguageName
											, _LanguageInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="LanguageCode">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(string LanguageCode)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_conf_LanguageDelete", LanguageCode);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListLanguageInfo(ref SqlDataReader dr, ref List<LanguageInfo> lstLanguage)
        {
            LanguageInfo _LanguageInfo = null;
            while (dr.Read())
            {
                _LanguageInfo = new LanguageInfo();
                setLanguageInfo(dr, ref _LanguageInfo);
                lstLanguage.Add(_LanguageInfo);
            }
        }

        private static void setLanguageInfo(SqlDataReader dr, ref LanguageInfo _LanguageInfo)
        {
			_LanguageInfo.LanguageCode = dr[LanguageDAL.FIELD_LANGUAGECODE] != DBNull.Value ? Convert.ToString(dr[LanguageDAL.FIELD_LANGUAGECODE]) : string.Empty;
			_LanguageInfo.LanguageName = dr[LanguageDAL.FIELD_LANGUAGENAME] != DBNull.Value ? Convert.ToString(dr[LanguageDAL.FIELD_LANGUAGENAME]) : string.Empty;
			_LanguageInfo.Description = dr[LanguageDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[LanguageDAL.FIELD_DESCRIPTION]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[conf_Language]";

        #endregion
    }
}

		